package com.sgai.dcac.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

import com.sgai.dcac.AppApplication;
import com.sgai.dcac.AppConstant;

import static com.sgai.dcac.AppConfig.LocalStorage.publicSharedPreferencesName;

/**
 * Created by tony on 2017/6/14.
 */

public class SharedPreferencesUtil {

    private static SharedPreferences sp;

    private static final String TAG = "SharedPreferencesUtil";

    static {
        Log.e(TAG,"AppApplication.getInstance() = " + AppApplication.getInstance());
        sp = AppApplication.getInstance().getSharedPreferences(publicSharedPreferencesName, Context.MODE_PRIVATE);
    }

    public static boolean isFirstExcute_1_0() {
        return sp.getBoolean(AppConstant.IS_FIRST_EXCUTE_1_0,true);
    }

    public static void setIsFirstExcute_1_0(boolean notFirstExcute_1_0) {
        sp.edit().putBoolean(AppConstant.IS_FIRST_EXCUTE_1_0,notFirstExcute_1_0);
    }

    public static String getServerUrl() {
        return sp.getString(AppConstant.SERVER_URL,"");
    }

    public static void setServerUrl(String serverUrl) {
        sp.edit().putString(AppConstant.SERVER_URL,serverUrl);
    }

    public static String getDeviceId() {
        return sp.getString(AppConstant.DEVICE_ID,"");
    }

    public static void setDeviceId(String deviceId) {
        sp.edit().putString(AppConstant.DEVICE_ID,deviceId);
    }

    public static String getNoticeNumberHead() {
        return sp.getString(AppConstant.NOTICE_NUMBER_HEAD,"");
    }

    public static void setNoticeNumberHead(String noticeNumberHead) {
        sp.edit().putString(AppConstant.NOTICE_NUMBER_HEAD,noticeNumberHead);
    }

    public String getReceiptNumberHead() {
        return sp.getString(AppConstant.RECEIPT_NUMBER_HEAD,"");
    }

    public static void setReceiptNumberHead(String receiptNumberHead) {
        sp.edit().putString(AppConstant.RECEIPT_NUMBER_HEAD,receiptNumberHead);
    }

    public static long getNoticeNumber() {
        return sp.getLong(AppConstant.NOTICE_NUMBER,-1);
    }

    public static void setNoticeNumber(long noticeNumber) {
        sp.edit().putLong(AppConstant.NOTICE_NUMBER,noticeNumber);
    }

    public static long getReceiptNumber() {
        return sp.getLong(AppConstant.RECEIPT_NUMBER,-1);
    }

    public static void setReceiptNumber(long receiptNumber) {
        sp.edit().putLong(AppConstant.RECEIPT_NUMBER,receiptNumber);
    }

    public static int getCacheKeepingTime() {
        return sp.getInt(AppConstant.CACHE_KEEPING_TIME,-1);
    }

    public static void setCacheKeepingTime(int cacheKeepingTime) {
        sp.edit().putInt(AppConstant.CACHE_KEEPING_TIME,cacheKeepingTime);
    }

    public static String getToken() {
        return sp.getString(AppConstant.TOKEN,"");
    }

    public static void setToken(String token) {
        sp.edit().putString(AppConstant.TOKEN,token);
    }

    public static String getUsername() {
        return sp.getString(AppConstant.USERNAME,"");
    }

    public static void setUsername(String username) {
        sp.edit().putString(AppConstant.USERNAME,username);
    }

    public static String getUserId() {
        return sp.getString(AppConstant.USER_ID,"");
    }

    public static void setUserId(String userId) {
        sp.edit().putString(AppConstant.USER_ID,userId);
    }

    public static boolean getLoginState() {
        return sp.getBoolean(AppConstant.LOGIN_STATE,false);
    }

    public static void setLoginState(boolean state) {
        sp.edit().putBoolean(AppConstant.LOGIN_STATE,state).commit();
    }


}
